import time

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.remote.webdriver import WebDriver

from base.base_page import BasePage
from page.main_page import MainPage


class App(BasePage):
    _agree_button = (AppiumBy.XPATH,
                     "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View[2]/android.view.View/android.view.View[4]")

    @classmethod
    def start(cls):
        caps = dict()
        caps["platformName"] = "Android"
        caps["deviceName"] = "yeshen"
        caps["appPackage"] = "me.hxyfj.rk"
        caps["appActivity"] = "com.uzmap.pkg.EntranceActivity"
        caps["autoGrantPermissions"] = "true"
        caps["ensureWebviewsHavePages"] = True
        driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        time.sleep(4)
        driver.find_element(AppiumBy.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View[2]/android.view.View/android.view.View[4]").click()

        return MainPage(driver)
